package com.yoda.youdianda.vo;

import com.yoda.youdianda.domain.SysRole;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Objects;

/**
 * @author shawn
 * @date 2022年 11月 14日 17:16
 * 根据查询各角色对应的功能
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
// todo 优化
public class RoleInfoVo {
    private String id;
    private String name;
    private String description;
    private String create_date;
    private String update_date;
    private String del_flag;
    private Integer superadmin;
    private String default_data;
    private List<MenuDetailVo> authList;

    public static RoleInfoVo init(SysRole role, SimpleDateFormat format) {
        RoleInfoVo vo = new RoleInfoVo();
        BeanUtils.copyProperties(role, vo);
        vo.setDel_flag(role.getDelFlag());
        vo.setDefault_data(role.getDefaultData());
        vo.setCreate_date(format.format(role.getCreateDate()));
        if (!Objects.isNull(role.getUpdateDate())) {
            vo.setUpdate_date(format.format(role.getUpdateDate()));
        }
        return vo;
    }
}
